-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Emscripten build (demo, quick and dirty) #12
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth merging IMO even if not for Emscripten, then for cleaning up the main sequence at the very least
checkpoint = "model.bin"; | ||
FILE *file = fopen(checkpoint, "rb"); | ||
if (!file) { | ||
printf("Unable to open file!"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
printf("Unable to open file!"); | |
printf("Unable to open file!"); | |
return 1; |
{ | ||
FILE *file = fopen("vocab.bin", "r"); | ||
if (!file) { | ||
printf("Unable to open file!"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
printf("Unable to open file!"); | |
printf("Unable to open file!"); | |
return 1; |
Very cool ty! I'm not as familiar with emscripten, I'll take some time to look at this and whether there is a way to support it gracefully. |
@ggerganov one thing I really like is the tokenizer inside C here, removing the need to use the run_wrap.py and sentencepiece. But it's not clear how you produced vocab.bin, presumably it's an export script? |
nvm got it working in 3bfa566 |
Yes, for this PR I had exported the vocab from I'm not sure about the cause of the leading space - we have it in |
The tokenizer stores a leading space on some tokens. In python we use the But this repo is using the python3
>>> import sentencepiece as spm
>>> sp = spm.SentencePieceProcessor(model_file='tokenizer.model')
>>> sp.id_to_piece([9038])
['▁Once'] Then it is simply printed, without considering if it is the first token: Line 471 in f565089
The PR #89 fixes it |
I recreated @ggerganov's changes against the current tree (with support for prompt): https://github.com/gohai/llama2.c/commits/emscripten |
I've built a JS framework around this idea to run Language Models on Web. llama2.c on Web Demo: https://rahuldshetty.github.io/ggml.js-examples/llama2_tinystories.html |
This is a very ugly hack to demonstrate build with Emscripten
Not intended to merge as it will just ruin the beauty of the implementation and most likely there is a much better way to do this. Mainly for educational purposes.
The
vocab.bin
is generated in a similar way explained in #9The produced artifacts will be generated in the
web
subfolder.Example: https://ggerganov.com/llama2.c